<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<html>
	<head>
		<title>流程实例管理</title>
		<%@ include file="/common/meta.jsp"%>
		<%@ include file="/common/jquery-ui-inc.jsp"%>
		<script>
//$.messager.defaults={ok:"确定",cancel:"取消"};   

$(function() {
	$('#lockList').datagrid( {
		title : '流程实例列表',
		url : '${ctx}/flow/core/flow-instance!data.action',
		loadMsg : '数据载入中，请稍后……',
		nowrap : false,
		collapsible : false,
		fitColumns : true,
		pagination : true,
		singleSelect : false,
		rownumbers : true,
		remoteSort : false,
		method: 'POST',
		pageList : [15, 30, 50],
		idField : 'id',
		onLoadSuccess:function(){  
		  $('#lockList').datagrid('clearSelections');
		},
		columns : [ [ 
		{
			field : 'id',
			title : '实例Id',
			width : 220,
			sortable:true,
			sorter : function(a, b) {
				return (a > b ? 1 : -1);
			}
		}, {
			field : 'name',
			title : '流程名',
			width : 120,
			sorter : function(a, b) {
				return (a > b ? 1 : -1);
			}
		}, {
			title : '流程key',
			field : 'key',
			width : 100
		},{
			title : '流程定义Id',
			field : 'definitionId',
			width : 200
		},{
			title : '是否挂起',
			field : 'isSuspended',
			width : 200,
			formatter: function(val, rec,rowIndex){
				if(val=="true")return "<span style='color:red;'>已挂起</span>";
				else{
					return "<span style='color:green;'>正常</span>";
				}
			}
		},{
			title : '是否结束',
			field : 'isEnd',
			width : 200,
			formatter: function(val, rec,rowIndex){
				if(val=="true")return "<span style='color:red;'>已结束</span>";
				else{
					return "<span style='color:green;'>未结束</span>";
				}
			}
		}
		,{
			title : '操作',
			field : 'cz',
			width : 200,
			formatter:function(value,row,index){
				return '<a href="javascript:viewProcessPic(\''+row.id+'\')" >查看流程图</a>      <a href="javascript:delProcess(\''+row.id+'\')">删除流程</a>';
			}
		}] ]
	});
});

	//删除流程实例
	function delProcess(id) {
			$.messager.confirm('确认', '您确定要删除:<font color="red">' + id + '</font> ？',
					function(r) {
						if (r) {
							$.ajax( {
								type : "post",
								url : "${ctx}/flow/core/flow-instance!del.action?processInstanceId="+ id,
								dataType:'json',
								beforeSend : function(XMLHttpRequest) {
									//ShowLoading();
								},
								success : function(data, textStatus) {
									var f = data.flag;
									if(f == "T"){
										$.messager.alert('结果', data.msg, 'info',function(){
											reload();
										});
									}else{
										$.messager.alert('错误', data.msg, 'error');
									}
									
								},
								complete : function(XMLHttpRequest, textStatus) {
									//HideLoading();
								},
								error : function() {
									//请求出错处理
								}
							});
						}
			});
	}
	
	
	//查看流程图
	function viewProcessPic(id){
		var url = "${ctx}/flow/core/flow-view-pic.action?processInsId="+id;
		$("#lockAddFrame").attr("src",url);
		$('#lockAddWin').window('open');
	}

	function reload(){
		$('#lockList').datagrid("reload");
	}
	
	function closeAddWin(){
		$('#lockAddWin').window('close');
	}

	function searchList(){					
	 	var queryParams = $('#lockList').datagrid('options').queryParams;	    
	       	var opt = $('#lockList').datagrid('options'); 
	       	 $('#lockList').datagrid('options').pageNumber=1;
	        queryParams["processDefinitionId"] = $('#processDefinitionId').val();
	        queryParams["processInstanceId"] = $('#processInstanceId').val();
	        $('#lockList').datagrid('reload');
	         var page = $('#lockList').datagrid('getPager');
			page.pagination({pageNumber:1,pageSize:opt.pageSize});
	  }
	  
	function clearSearch(){					
	   $('#processDefinitionId').val('');
       $('#processInstanceId').val('');
		searchList(); 
	  }    
			
	</script>
	</head>

	<body>
	
	<div title="查询" id="list"  class="easyui-panel" icon="icon-search"  collapsible="true">
	 <form action="" id="searform" name="searform" method="post">
        <table class="info"  cellpadding="0" cellspacing="1" id="searProIns">
                <tr>                   
                     <td class="datagrid-header">&nbsp;流程定义id：</td>
             		 <td> <input type=text id="processDefinitionId" name="processDefinitionId" value="" size=20 />&nbsp;&nbsp; </td>
             		   <td class="datagrid-header">流程实例id：</td>
                 <td> <input type=text id="processInstanceId" name="processInstanceId" value="" size=20 /> </td>    <td>&nbsp;<a class="easyui-linkbutton" iconCls="icon-search" onClick="searchList()">查 询</a>&nbsp;<a class="easyui-linkbutton" iconCls="icon-cut" onClick="clearSearch();">清空</a></td>          
                 </tr>  
            </table>
        </form>
        </div>
	
		<table id="lockList"></table>

		<div id="lockAddWin" class="easyui-window" title="查看流程图"
			style="padding: 5px; width: 1000px; height: 500;" 
			iconCls="icon-search" closed="true" maximizable="false"
			minimizable="false" collapsible="false" >
			<iframe frameborder="0" id="lockAddFrame" height="100%" width="100%"
				scrolling="yes" frameborder="0" style="position:relative;"></iframe>
		</div>

	</body>
</html>